import pandas as pd
from settings import STOCK_ID_NAME_JSON
import json
if __name__ == "__main__":
    data = pd.read_excel('required.xlsx')
    required_stocks = []
    dic_info = {}
    with open(STOCK_ID_NAME_JSON, 'r', encoding="utf-8_sig") as f:
        dic_info = json.load(f)
    for id in set(data['名称1对应'].to_list()+data['证券代码'].to_list()):
        x = str(id)
        while len(x) < 6:
            x = "0"+x
        # print(x)
        required_stocks.append(x)
        dic_info.update({str(x):str(x)})
    print(len(required_stocks))
    with open(STOCK_ID_NAME_JSON, 'w', encoding="utf-8") as f:
        json.dump(dic_info, f)
    with open("required_posting_list.txt", 'a+', encoding="utf-8_sig") as f:
        for id in required_stocks:
            f.write(f"{id}\n")
            print(f"{id}\n")


    
